package com.aruba.service.impl;

import com.aruba.bean.Order;
import com.aruba.fegin.StockClient;
import com.aruba.mapper.OrderMapper;
import com.aruba.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private StockClient stockClient;

    @Override
    @GlobalTransactional// 开启分布式事务
    public void addOrder() {
        Order order = new Order(null, 1, "新增订单");
        orderMapper.insert(order);
        stockClient.reduceStock(1);
    }
}
